Left Recursion in Parsing Expression Grammars

نویسندگان

  • Sérgio Medeiros
  • Fabio Mascarenhas
  • Roberto Ierusalimschy
چکیده

Parsing Expression Grammars (PEGs) are a formalism that can describe all deterministic context-free languages through a set of rules that specify a top-down parser for some language. PEGs are easy to use, and there are efficient implementations of PEG libraries in several programming languages. A frequently missed feature of PEGs is left recursion, which is commonly used in Context-Free Grammars (CFGs) to encode left-associative operations. We present a simple conservative extension to the semantics of PEGs that gives useful meaning to direct and indirect left-recursive rules, and show that our extensions make it easy to express left-recursive idioms from CFGs in PEGs, with similar results. We prove the conservativeness of these extensions, and also prove that they work with any left-recursive PEG.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Direct Left-Recursive Parsing Expression Grammars

Parsing Expression Grammars (PEGs) are specifications of unambiguous recursive-descent style parsers. PEGs incorporate both lexing and parsing phases and have valuable properties, such as being closed under composition. In common with most recursive-descent systems, raw PEGs cannot handle left-recursion; traditional approaches to left-recursion elimination lead to incorrect parses. In this pape...

متن کامل

Compact non-left-recursive grammars using the selective left-corner transform and factoring

The left-corner transform removes left-recursion from (probabilistic) context-free grammars and unication grammars, permitting simple top-down parsing techniques to be used. Unfortunately the grammars produced by the standard left-corner transform are usually much larger than the original. The selective left-corner transform described in this paper produces a transformed grammar which simulates...

متن کامل

A New Top-Down Parsing Algorithm for Left-Recursive DCGs

Abs t rac t . In this paper we introduce a new parsing algorithm, called cancellation parsing. Deterministic cancellation parsing with lookahead k can handle the C(k) grammars, which include the LL(k) grammars and are contained in the LC(k) grammars. The C(k) property is of theoretical interest in that it shows how to formalize the intuitive notion of the LL(k) property extended with the possib...

متن کامل

Simple, Efficient, Sound and Complete Combinator Parsing for All Context-Free Grammars, Using an Oracle

Parsers for context-free grammars can be implemented directly and naturally in a functional style known as “combinator parsing”, using recursion following the structure of the grammar rules. Traditionally parser combinators have struggled to handle all features of context-free grammars, such as left recursion. Previous work introduced novel parser combinators that could be used to parse all con...

متن کامل

Increasing the Applicability of LR Parsing

In this paper we discuss a phenomenon present in some context-free grammars, called hidden left recursion. We show that ordinary LR parsing according to hidden left-recursive grammars is not possible and we indicate a range of solutions to this problem. One of these solutions is a new parsing technique, which is a variant of traditional LR parsing. This new parsing technique can be used both wi...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2012